<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateProjectStepReviewWorkflowRelationTable extends AbstractMigration
{

    public function up()
    {
        $table = $this->table('project_step_review_workflow_relation', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);

        //添加数据字段
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '关系ID'])
            ->addColumn('step_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '工序ID'])
            ->addColumn('review_workflow_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '审批流配置ID'])
            ->addColumn('uuid', 'char', ['default' => '', 'limit' => 36, 'comment' => '全局唯一标识符'])
            ->addColumn('project_id', 'integer', ['default' => 0, 'null' => false, 'limit' => 11, 'comment' => '工序流id'])
            ->addColumn('attr_str', 'string', ['default' => '', 'null' => false, 'limit' => 256, 'comment' => '属性attr'])
            ->addColumn('step_workflow_id', 'integer', ['default' => 0, 'null' => false, 'limit' => 11, 'comment' => '工序流id'])
            ->addColumn('review_node_config', 'json', ['null' => true, 'comment' => '审核人员配置'])
            ->addIndex(['project_id', 'step_workflow_id', 'step_id', 'attr_str'], ['type' => 'unique', 'name' => 'idx_unique_step_workflow_attr'])
        ;

        //执行创建
        $table->create();
    }

    public function down()
    {
        $this->table('project_step_review_workflow_relation')->drop()->save();
    }
}
